#include <iostream>
#include "Liste.h"
#include <malloc.h>
#include <ctype.h>
using std::cout;
using std::cin;
Liste::Liste(){
char c;
                insd_P();
                cout<<"Adaugati elemente ? (D/N): ";
                cin>>c;c=toupper(c);
                while(c=='D')
                 {
                         insd_Cs();
                         cout<<"Mai adaugati elemente ? (D/N): ";
                         cin>>c;c=toupper(c);
                }
}
void Liste::listare(void)
        {
                x=p;
                while(x!=NULL)
                 {
                         cout<<"Cheia : "<<x->cheie;
                         x=x->urm;
                 }
        } /* Listare */
void Liste::insd_P(void)
        {
                q=(ref)malloc(sizeof(Tnod));
                cout<<"Cheia : ";cin>>q->cheie;
                q->urm=NULL;
                q->ant=NULL;
                p=q;
        } /* Insd_p */
void Liste::insd_Cs(void)
        {
                s=(ref)malloc(sizeof(Tnod));
                cout<<"Cheia : ";cin>>s->cheie;
                s->urm=NULL;
                q->urm=s;
                q=s;
        } /* Insd_cs */
bool Liste::operator ==(Liste& right)
{
    r=p;
    right.r=right.p;
    int x=1;
    while(r!=NULL && right.r!=NULL)
    {
        if(r->cheie!=right.r->cheie)
            x=0;

        r=r->urm;
        right.r=right.r->urm;
    }
    if(x!=0)
        return true;
    return false;
}
bool Liste::operator !=(Liste& right)
{
    r=p;
    right.r=right.p;
    int x=1;
    while(r!=NULL && right.r!=NULL)
    {
        if(r->cheie!=right.r->cheie)
            x=0;
        r=r->urm;
        right.r=right.r->urm;
    }
    if(x==0)
        return true;
    return false;
}
Nod::Nod(){
insd_Cs();
}
void Nod::insd_Cs(){
                s=(ref)malloc(sizeof(Tnod));
                cout<<"Cheia : ";cin>>s->cheie;
                s->urm=NULL;
                q->urm=s;
                q=s;
}
void Nod::listare(){
                        x=q;
                while(x!=NULL)
                 {
                         cout<<"Cheia : "<<x->cheie;
                         x=x->urm;
                 }
}
Liste Liste::operator +(Nod& right){
                right.s->urm=NULL;
                q->urm=right.s;
                q=right.s;

}

